import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [{
      path: 'index',
      name: '首页',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'home' }
    }]
  },
  {
    path:'/blogger',
    component: Layout,
    redirect: '/blogger',
    name: '博主',
    meta: {
      title: '博主',
      icon: 'el-icon-user'
    },
    children:[
      {
        path: 'skill',
        name: '我的技能',
        component: () => import('@/views/blogger/skill'),
        meta: { title: '我的技能', icon: 'skill' }
      },
      {
        path:'label',
        name:'我的标签',
        component:()=>import('@/views/blogger/myLabel'),
        meta: {title:'我的标签',icon:'label'}
      },
      {
        path:'contact',
        name:'与我联系',
        component:()=>import('@/views/blogger/contact'),
        meta: {title:'与我联系',icon:'contact'}
      },
      {
        path:'humor',
        name:'轻松时刻',
        component:()=>import('@/views/blogger/humor'),
        meta: {title:'轻松时刻',icon:'humor'}
      },
      {
        path:'story',
        name:'我的故事',
        component:()=>import('@/views/blogger/story'),
        meta: {title:'我的故事',icon:'story'}
      },
      {
        path:'ending',
        name:'故事的结尾',
        component:()=>import('@/views/blogger/ending'),
        meta: {title:'故事的结尾',icon:'ending'}
      }
    ]
  },
  {
    path:'/article',
    component: Layout,
    redirect: '/article',
    name: '文章',
    meta: {
      title: '文章',
      icon: 'el-icon-tickets'
    },
    children:[
      {
        path: 'articleList',
        name: '文章列表',
        component: () => import('@/views/article/articleList'),
        meta: { title: '文章列表', icon: 'el-icon-document-copy' }
      },
      {
        path: 'addArticle',
        name: '添加文章',
        component: () => import('@/views/article/addArticle'),
        meta: { title: '添加文章', icon: 'el-icon-document-add' }
      },
      {
        path: 'editArticle',
        name: '编辑文章',
        hidden:true,
        component: () => import('@/views/article/editArticle'),
        meta: { title: '编辑文章', icon: 'el-icon-document-add' }
      }
    ]
  },
  {
    path:'/articleType',
    component: Layout,
    redirect: '/articleType',
    name: '文章栏目',
    meta: {
      title: '文章栏目',
      icon: 'el-icon-menu'
    },
    children:[
      {
        path: 'typeList',
        name: '栏目列表',
        component: () => import('@/views/type/typeList'),
        meta: { title: '栏目列表', icon: 'el-icon-document-copy' }
      },
      {
        path: 'addType',
        name: '添加栏目',
        component: () => import('@/views/type/addType'),
        meta: { title: '添加栏目', icon: 'el-icon-document-add' }
      },
      {
        path: 'editType',
        name: '编辑栏目',
        hidden:true,
        component: () => import('@/views/type/editType'),
        meta: { title: '添加栏目', icon: 'el-icon-document-add' }
      }
    ]
  },
  {
    path:'/vpn',
    component: Layout,
    redirect: '/vpn',
    name: 'vpn',
    meta: {
      title: 'vpn',
      icon: 'el-icon-menu'
    },
    children:[
      {
        path: 'addVpn',
        name: '添加vpn',
        component: () => import('@/views/vpn/index'),
        meta: { title: '添加vpn', icon: 'el-icon-document-copy' }
      }
    ]
  },
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: 'Nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: 'menu2' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
